#ifndef TRANSFORMERCONTENTBUFFER_HPP_3
#define TRANSFORMERCONTENTBUFFER_HPP_3
/*************************************
 * alloc big block space for client process.
 * notice: all thread use the same buffer
 * one port use a storage class
 ***************************************/
#include "transContentDefine.h"
#include "transContentErrorCode.h"
#include "transContentSetting.hpp"
#include "logger.hpp"


class TransContentMemory{
	public:
		//buffer state
		static const int BUFFER_BUSY;
		static const int BUFFER_FREE;

	private:
		static TransContentMemory* _instance;
		int mRecordCount;
		int mRecordSize;
		int mUsedRecordCount;
		int mState;
		char* bufferBase;
		char* bufferStateArray;

		pthread_mutex_t mMutexBuffer;

	public:
		static TransContentMemory* getInstance();
		static void releaseInstance();

		int getRecordCount() const ;
		int getRecordSize() const;

		//size
		int getUsedRecordCount();
		int getFreeRecordCount();

		int getState();

		//buffer
		int getBuffer(char** record);
		int releaseBuffer(int recordIndex);

		//indexToPoint
		char* indexToBuffer(int index);

	private:
		TransContentMemory();
		~TransContentMemory();
		int allocMemroy();
		int freeMemory();
		int increaseBuffer();
};
#endif //TRANSFORMERCONTENTBUFFER_HPP_3
